/**
 * 进程扇
 *  所谓的进程扇就是一个父进程创建出多个子进程
 * 
 * gcc -g -rdynamic -I include    -O0 -Wall  -o obj/progress_fan src/progress_fan.c
 * obj/progress_fan 5
 * pstree -p 3629
*/


#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    int count = 0;
    if (argc < 2)
    {
        count = 1;
    }
    else
    {
        count = atoi(argv[1]);
    }
    int i = 0;
    for (; i < count; ++i)
    {
        pid_t pid = fork();
        if (0 > pid)
        {
            perror("fork error: ");
            exit(EXIT_FAILURE);
        }
        else if (0 == pid)
        {
            break;
        }
    }

    printf("I am pid is %d, I am ppid is %d\n", getpid(), getppid());
    while(1){
        sleep(1);
    }
    return 0;
}